package com.kaishengit.demo.thread;

public class Test {


    //1.join线程
    //当某个程序在执行过程中调用了其他线程的join()方法，则当前线程被阻塞，直到被join()方法加入的线程完成为止。
    public static void main(String[] args) throws InterruptedException {

        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                for (int i=0;i<10;i++){
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName()+"-hello-"+i);

                }
            }
        };

        Thread thread = new Thread(runnable);
        for (int i=0;i<10;i++){
            Thread.sleep(100);
            if (i==5){
                thread.start();
                thread.join();
            }
            System.out.println(Thread.currentThread().getName()+"-hello-"+i);
        }
    }


    //2.守护线程
    //主线程死亡，无论守护线程是否允许完毕，都会死亡
    /*public static void main(String[] args) throws InterruptedException {

        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                for (int i=0;i<10;i++){
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName()+"-hello-"+i);
                }
            }
        };

        Thread thread = new Thread(runnable);

        for (int i=0;i<10;i++){
            if (i==5){
                thread.setDaemon(true);
                thread.start();
            }
            Thread.sleep(100);
            System.out.println(Thread.currentThread().getName()+"-hello-"+i);
        }
    }*/


    //3.线程同步问题
    /*public static void main(String[] args) {

        Account account = new Account();
        Boy boy = new Boy(account);
        boy.start();

        Girl girl = new Girl(account);
        girl.start();
    }*/
}
